<%@page import="org.siscoh.controller.ControlePermissao"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    request.setAttribute("minper", 1);
    
    if(!ControlePermissao.possuiPermissao(request, response))
    {
        %> <jsp:include flush="true" page="/403.html" />  <%
        return;
    }
%>

<html>
  <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
      
    <title>Cadastro de Categoria</title>
  <!--
	-->	
	<script type="text/javascript" language="javascript" src="script/jquery.min.js" ></script>
	<script>
		var qtdespec = 1;
		
		//4 partes
		var tr = new Array ('<tr hidden id="trespec',
				'"><td>Especificação:</td><td><input style="vertical-align: middle;" id="especificacao',
				'" name="especificacao',
				'" type="text" maxlength="50" size="50" onkeypress="">'+
                                //Linha dicionada:
                                '<span id="spanadd"></span>'+
                                /*
                                '<a href="javascript:processar()">'+
                                '<input style="vertical-align: middle;" type="image" id="addbutton"'+
				'src="imagens/icones/mais2.png" title="nova especificação" value=""/></a>'+*/
                                '</td></tr>');
		
		function getHtmlTr(indice)
		{
                    return tr[0]+indice+tr[1]+indice+tr[2]+indice+tr[3];
		}
		
	</script>
  </head>
  
<body bgcolor='gray'>
	  
<jsp:useBean class="org.siscoh.controller.Constants" id="constants" scope="page" />
<form name="" method="POST" action="Controlador?action=Categoria&cod=${constants.insertCategoria}" >
  <!--<div style="border: 1px solid black; width: 120px; padding: 0px; margin: 0px; ">-->
<br>
<input type="hidden" id="qtdespec" value="1" >
<div align="center">
<table id="cattable" cellspacing="5" rules="" border="0">
    <tr>
        <td colspan="2" bgcolor="">
            <div id="" align="center">Cadastro de Categoria</div>
        </td>
    </tr>        
    <tr>
      <td>Nome da Categoria:</td>
      <td><input name='nomecategoria' id='nomecategoria' type='text' size='50'></td>
    </tr>
    <tr id="trespec0">
      <td>Especificação:</td>
      <td><div><input style="vertical-align: middle;" name='especificacao0' id='' type='text' maxlength='50' size='50' onkeypress="">
              <span id="spanadd">
              <a href="javascript:processar()">
                  <img style="vertical-align: middle;" id="addbutton" title="nova especificação"
                    src="imagens/icones/mais2.png" value=""/>
              </a>
              </span>
          </div>
      </td>
    </tr>
</table>
    
   <input class="" type="submit" value="Cadastrar" >
<br />
<br />
    <c:if test="${param.status != null}">
        <c:if test="${param.status == 1}">
            <span id="status" class="success">Categoria cadastrada com sucesso!</span>
            <script>
                hideStatus();
            </script>
        </c:if>
        <c:if test="${param.status != 1}">
            <span id="status" class="error">Erro ao cadastrar a categoria!</span>
            <script>
                hideStatus();
            </script>
        </c:if>
    </c:if>
</div>
   <script>
       function processar() {
           var qtd = qtdespec;
            //var qtd = parseInt($("#qtdespec").val(),10);
            var str;
            var htmlA;
            
            //alert($("#addbutton").html());
            //$("#addbutton").remove();
            
            htmlA = $("#spanadd").html();
            $("#spanadd").remove();
				
            str = getHtmlTr(qtd);
            
            $("#cattable").append(
		str
            );
                
            $("#spanadd").html(
                htmlA
            );
            
            $("#cattable tr:last").fadeIn('slow');
            //alert(str);
			
            qtd++;
            
            qtdespec = qtd;            
            //$("#qtdespec").val(qtd);
        }
   </script>
  </form>
  </body>
</html>
